﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TjZheng.Mvc;
using TjZheng.SSO.Process;

namespace TjZheng.SSO.Web.Controllers
{
    public class SSOController : TjZhengController
    {
        public UserProcess CurrentUserProcess { get; private set; }

        public SSOController()
        {
            this.CurrentUserProcess = GetUserProcess();
        }

        public virtual UserProcess GetUserProcess()
        {
            return new UserProcess();
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual ActionResult GetUserInfo(string id)
        {
            return Json(CurrentUserProcess.GetUserInfo(id), JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public virtual ActionResult LoginIn(string userName, string password)
        {
            return Json(CurrentUserProcess.LoginIn(userName, password), JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="id"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="repassword"></param>
        /// <returns></returns>
        public virtual ActionResult Register(string userName, string password, string rePassword)
        {
            return Json(CurrentUserProcess.Register(userName, password, rePassword), JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 用户注销
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual ActionResult LoginOut(string id)
        {
            return Json(CurrentUserProcess.LoginOut(id), JsonRequestBehavior.AllowGet);
        }
    }
}
